package com.xbai.spark.recall

import com.xbai.spark.recall.engine.{ItemCFEngine, UserCFEngine}
import org.apache.spark.sql.{DataFrame, SparkSession}

/**
  * @author xbai
  * @Date 2021/1/14
  */
class RecallItem(spark: SparkSession) {

  private val userEngine = new UserCFEngine(spark)
  private val itemEngine = new ItemCFEngine(spark)

  def recallFromUserCFEngine(userId: String): DataFrame = {
    userEngine.init()
    val users: DataFrame = userEngine.getSimilarUsers(userId, 15)
    val items: DataFrame = userEngine.getItemsBySimilarUser(users)
    items
  }

  def recallFromItemCFEngine(itemId:String): DataFrame = {
    itemEngine.init()
    val items: DataFrame = itemEngine.getSimilarItems(itemId, 15)
    items
  }

  def recallFromItemJaccardCFEngine(itemId:String): DataFrame = {
    itemEngine.init()
    val items: DataFrame = itemEngine.getJaccardSimilarItems(itemId, 15)
    items
  }
}
